package com.cyt.web.controller.work.wb;

import com.cyt.base.enums.BusinessType;
import com.cyt.base.enums.OperatorType;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.base.util.StringUtils;
import com.cyt.work.wb.model.po.WbServicer;
import com.cyt.work.wb.model.po.WbUser;
import com.cyt.work.wb.model.vo.WbUserVo;
import com.cyt.work.wb.service.WbServicerService;
import com.cyt.work.wb.service.WbUserService;
import com.cyt.sys.aspect.BaseLog;
import com.cyt.web.controller.base.BaseController;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 维保模块_人员信息-人员信息控制层
 *
 * @author shengQiang Yu
 * @date 2019-11-28 15:14:32
 */
@RestController
public class WbUserController extends BaseController {

    @Resource
    private WbUserService wbUserService;

    @Resource
    private WbServicerService wbServicerService;

    /**
     * 统一跳转
     *
     * @return Model
     * @author shengQiang Yu
     * @date 2019-11-28 15:14:32
     */
    @RequestMapping("/work/wb/wbuser/{pageName}")
    public ModelAndView goPage(@PathVariable("pageName") String pageName, String applyId, String servicerId) {
        ModelAndView view = new ModelAndView("/work/wb/wbuser/"+pageName);
        view.addObject("applyId", applyId);
        view.addObject("servicerId", servicerId);
        return view;
    }

    /**
     * 分页查询
     *
     * @param wbUserVo 接受参数对象
     * @param page 当前页面
     * @param limit 页面数量
     * @return ReturnResult
     * @author shengQiang Yu
     * @date 2019-11-28 15:14:32
     */
    @BaseLog(module = "维保模块_人员信息", classz = "人员信息", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/wb/wbuser/page", method = RequestMethod.POST)
    public ReturnResult page(WbUserVo wbUserVo, int page, int limit) {
        return wbUserService.page(wbUserVo, page, limit);
    }

    /**
     * 跳转添加或编辑界面
     *
     * @param id 主键
     * @return ReturnResult
     * @author shengQiang Yu
     * @date 2019-11-28 15:14:32
     */
    @BaseLog(module = "维保模块_人员信息", classz = "人员信息", methods = "跳转添加或编辑界面", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/wb/wbuser/getEdit", method = RequestMethod.GET)
    public ModelAndView getEdit(String id,String applyId,String servicerId) {
        ModelAndView view = new ModelAndView("/work/wb/wbuser/wbUserEdit");
        WbUser wbUser=new WbUser();
        if (StringUtils.isNotBlank(id)) {
            wbUser=wbUserService.selectByPrimaryKey(id);
            if(StringUtils.isNotBlank(wbUser.getServicerId())){
                WbServicer wbServicer=wbServicerService.selectByPrimaryKey(wbUser.getServicerId());
                wbUser.setServicerId(wbServicer.getId());
                wbUser.setServicerIdName(wbServicer.getName());
            }
        }
        if(StringUtils.isNotBlank(servicerId)){
            WbServicer wbServicer=wbServicerService.selectByPrimaryKey(servicerId);
            wbUser.setServicerId(wbServicer.getId());
            wbUser.setServicerIdName(wbServicer.getName());
        }
        wbUser.setApplyId(applyId);
        view.addObject(wbUser);
        return view;
    }

    /**
     * 保存或更新
     *
     * @param request 请求对象
     * @param wbUserVo 接受参数对象
     * @return ReturnResult
     * @author shengQiang Yu
     * @date 2019-11-28 15:14:32
     */
    @BaseLog(module = "维保模块_人员信息", classz = "人员信息", methods = "保存或更新对象", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/wb/wbuser/addOrUpdate", method = RequestMethod.POST)
    public ReturnResult addOrUpdate(HttpServletRequest request, WbUserVo wbUserVo) {
        wbUserVo.setApplyId(acceptCurrentApplyId(request).getId());
        return wbUserService.addOrUpdate(wbUserVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件逻辑删除
     *
     * @param request 请求对象
     * @param wbUserVo 接受参数对象
     * @return ReturnResult
     * @author shengQiang Yu
     * @date 2019-11-28 15:14:32
     */
    @BaseLog(module = "维保模块_人员信息", classz = "人员信息", methods = "逻辑删除对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/wb/wbuser/remove", method = RequestMethod.GET)
    public ReturnResult remove(HttpServletRequest request, WbUserVo wbUserVo) {
        return wbUserService.remove(wbUserVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件物理删除
     *
     * @param request 请求对象
     * @param wbUserVo 接受参数对象
     * @return ReturnResult
     * @author shengQiang Yu
     * @date 2019-11-28 15:14:32
     */
    @BaseLog(module = "维保模块_人员信息", classz = "人员信息", methods = "物理对象对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/wb/wbuser/delete", method = RequestMethod.GET)
    public ReturnResult delete(HttpServletRequest request, WbUserVo wbUserVo) {
        return wbUserService.delete(wbUserVo, acceptCurrentUser(request));
    }
}